package com.wx.tgp.designpattern.FactoryModePattern.SimpleFactory;

import java.util.Scanner;

/**
 * Created by Administrator on 2016/9/1.
 */
public class Program {

    public static void main(String args[]){
        int num1 = 0;
        int num2 = 0;
        String str3 = "";
        Scanner scanner = new Scanner(System.in);
            while(true){
                System.out.println("请输入第一个数：");
                String str1 = scanner.nextLine();
                try{
                    num1 = Integer.parseInt(str1);
                } catch (Exception e){
                    System.out.println("不能输入字符，请重新输入");
                    continue;
                }
                break;
            }
            while(true){
                System.out.println("请输入第二个数");
                String str2 = scanner.nextLine();
                try{
                    num2 = Integer.parseInt(str2);
                } catch (Exception e){
                    System.out.println("不能输入字符，请重新输入");
                    continue;
                }
                break;
            }
            while(true){
                System.out.println("请输入运算字符('+','-','*','/')：");
                str3 = scanner.nextLine();
                if("+".equals(str3)||"-".equals(str3)||"*".equals(str3)||"/".equals(str3)){
                    if("+".equals(str3)){
                        System.out.println(num1 + " + " + num2 + " = " + (num1 + num2));
                    } else if("-".equals(str3)){
                        System.out.println(num1 + " - " + num2 + " = " + (num1 - num2));
                    } else if("*".equals(str3)){
                        System.out.println(num1 + " * " + num2 + " = " + (num1 * num2));
                    } else if("/".equals(str3)){
                        if(num2 == 0 ){
                            System.out.println("除数不能为0，谢谢！");
                        }else{
                            System.out.println(num1 + " / " + num2 + " = " + (num1 / num2));
                        }
                    }
                    break;
                }else{
                    continue;
                }
            }




    }
}
